WEBVTT

00:01.740 --> 00:03.650
Hello and welcome back to our costs.

00:03.710 --> 00:10.660
So in the last session I introduced multi-dimensional and umpire race and the most common cases to remember

00:10.760 --> 00:14.310
a case where we have rows and columns.

00:14.310 --> 00:20.630
Some of this session we learn how to index that slides two dimensional arrays and also how to change

00:20.640 --> 00:24.030
singer or multiple elements in a two dimensional array.

00:24.650 --> 00:28.650
So about first of all let's s always important umpire.

00:29.220 --> 00:37.670
And then we create an umpire Ray from 1 to twelfth including and then we reshape those 12 elements to

00:37.770 --> 00:43.380
three rows and four columns.

00:43.390 --> 00:47.000
Now you could ask yourself why the elements are arranged in this manner.

00:47.080 --> 00:49.050
So we have kind of a row vice order.

00:49.060 --> 00:55.540
So we have twelve elements and reshape automatically orders them the elements row so starting in the

00:55.540 --> 00:57.600
first row one two three four.

00:57.640 --> 00:59.960
Then the second row of five six seven eight.

01:00.220 --> 01:02.710
And theoretically could also be the other way around.

01:02.710 --> 01:09.410
So starting column biased so one two three four five six and the others.

01:09.440 --> 01:11.790
And that this is the default setting and an umpire.

01:11.800 --> 01:14.790
But of course we can't change that soon.

01:14.840 --> 01:17.470
They reshape method.

01:17.520 --> 01:22.920
There is some part of me to court order and it's the default setting and see I don't want to go into

01:22.920 --> 01:33.660
details what C means but we can change here the order to F and when we rerun here ourselves then we

01:33.660 --> 01:34.710
get a different order.

01:34.710 --> 01:37.790
So now we have one two three four five six and so on.

01:37.800 --> 01:40.100
So this is flexible here.

01:40.140 --> 01:46.410
All right so let's change it to order C and run the sides again.

01:46.410 --> 01:54.420
Now again we f our let's say normal order and indexing multi-dimensional or two dimensional arrays.

01:54.460 --> 01:58.330
That's actually no difference to one dimensional arrays.

01:58.450 --> 02:05.880
So we have also zero based indexing and if we want to slice the first element of the array.

02:05.890 --> 02:08.760
So the first element here is the first row.

02:08.860 --> 02:13.150
We can do this by having the 0 in the spare brackets

02:17.710 --> 02:24.850
and now we get to the first row of our array and we can also get the second row at an exposition one

02:26.540 --> 02:38.270
and the third row at to next position to so your f in and 0 in exposition 1 and in exposition 2 and

02:38.280 --> 02:44.340
we can also slice of the last show which is actually the third row.

02:44.400 --> 02:47.390
This gives us the same result.

02:47.440 --> 02:50.900
And what if now we want to slice them in the second row.

02:51.040 --> 02:54.500
The second element so let's say here.

02:54.530 --> 02:57.290
So we want to have in the second row The second element.

02:57.320 --> 03:00.970
The sixth and we can do this by having two spat brackets.

03:00.980 --> 03:05.390
So first of all let's cross the second one year out.

03:05.800 --> 03:09.410
So first of all we are slicing the second row.

03:09.920 --> 03:11.040
Yeah.

03:11.300 --> 03:17.780
And then from the second row we are getting the second element in exposition 1

03:22.610 --> 03:23.000
and extra.

03:23.000 --> 03:29.360
We do not need to spell brackets you can put this into once bad bracket separated by a comma.

03:29.390 --> 03:35.840
So the first position gets us in the row we want to slice into the second position gets us in the column

03:36.920 --> 03:40.310
so spat bracket one come out.

03:40.310 --> 03:44.380
One should give us the same as loud as them here above buffers two step records.

03:44.390 --> 03:47.860
And that's correct.

03:47.860 --> 03:54.510
So now we can also index the element in the third row and the last column column.

03:54.520 --> 04:03.200
So let's see what it is on the third row in the last column it's twelve let's check this out and we

04:03.200 --> 04:13.480
get twelve and out if you want to select a column so all rows and all elements in a column then we can

04:13.480 --> 04:23.650
say okay I want f all rows I have a double colon and then I want to have the first column.

04:23.650 --> 04:27.130
Now this gives us the complete first column 1 5 and 9

04:30.730 --> 04:38.810
So all arrows in the first column and of course we can also select for all rows in the second column

04:40.170 --> 04:40.830
to 610

04:45.430 --> 04:51.550
and also all rows in the last column five eight twelve.

04:51.570 --> 04:58.290
Now we can also do more complicated things like getting the elements in the first two rows and column

04:58.290 --> 05:01.420
2 and 3.

05:01.590 --> 05:07.350
So in the first two rows the elements 2 and 3 so 2 3 6 7

05:12.900 --> 05:15.070
Yeah.

05:15.200 --> 05:23.540
All right so let's go back to our array and what we can also do we can switch or change the x's or transpose

05:23.570 --> 05:31.100
the Xs so to say that yeah instead of having a year one two three four as the first row we want to have

05:31.100 --> 05:37.940
it as a first column and instead of having here in the first column 1 5 9 we want to have it as the

05:37.940 --> 05:45.080
first row and we can do this by the attribute t so T capital letter

05:48.650 --> 05:55.730
and then we see a we just transposed them the our the array we switched the axis and that's also the

05:55.730 --> 05:58.040
method transpose.

05:58.280 --> 06:02.450
So we have at the brackets you can see it's a method not an attribute.

06:02.450 --> 06:07.980
And this gives us the same result.

06:08.000 --> 06:14.600
All right so now let's assume let's go back to our India rate a let's assume you want to divide the

06:14.600 --> 06:22.220
last column by 4 and actually we want to change the last column.

06:22.220 --> 06:29.390
So let's first of all divide on elements by force so we select all rows.

06:29.390 --> 06:36.770
And the last column and we will divide each element by four and then we have to assign the new values

06:37.430 --> 06:38.570
to the last column.

06:38.570 --> 06:39.560
So we have to say

06:43.880 --> 06:47.780
so please for the last column please calculate new values

06:50.950 --> 06:55.510
and now if you check a day you can see them on the last column.

06:55.680 --> 06:58.540
We have divided all elements by far.

06:59.000 --> 07:06.140
Okay so let's uh rearrange our array a well we know it already and then we can take the sum of all elements.

07:06.140 --> 07:13.680
So that's uh the method that sum which sums of all elements in the matrix.

07:13.750 --> 07:20.720
So it's seventy eight in what we can also do we can take the sum of each column so we can.

07:21.020 --> 07:28.620
So we can take the sum of column 1 it's the 15 of column two it's 18 and so on and therefore we have

07:28.620 --> 07:30.780
to define the axis.

07:30.780 --> 07:39.080
So the axis is the argument or barometer of the sum method an axis equals zero means that we take the

07:39.080 --> 07:48.520
sum of each column or to say along the rows so we sum up along the rows let's see what we get so we

07:48.520 --> 07:52.550
get 15 or 15 a seal of the some of the first column we get 18.

07:52.580 --> 08:00.280
It's the sum of the second column 21 is the sum of the third column and 24 is the sum of the fourth

08:00.280 --> 08:04.490
column and we can also take the sum of each row.

08:04.490 --> 08:11.040
So this means you take the sum along the columns.

08:11.040 --> 08:13.890
So get we get 10 26 and 42.

08:13.890 --> 08:18.690
So the sum of the first row gives us a 10.

08:18.720 --> 08:25.320
Then the sum of the second draw gives us 26 and the sum of the third row gives us 42.

08:26.340 --> 08:30.440
That's also the method come some and come some early returns.

08:30.450 --> 08:33.870
The cumulative sum of all elements.

08:33.870 --> 08:35.880
So let's see what we get.

08:35.890 --> 08:38.610
It's a cumulative means we are starting from the first element.

08:38.670 --> 08:43.120
So 1 then we are adding the second gives us three.

08:43.350 --> 08:47.830
Then we are adding the third element gives us six.

08:48.270 --> 08:57.730
Adding the fourth element gives us 10 adding the fifth element gives 15 and so on and we can also take

08:57.730 --> 09:00.100
the cumulative sum for each column

09:03.430 --> 09:05.500
from our let's secure the first column.

09:05.510 --> 09:15.220
So we start with 1 then we add 5 to 6 then we add 9 to 15 and also the second column.

09:15.220 --> 09:27.460
We have 2 adding six men we have eight adding 10 then we have 18 and we can also do the same cumulative

09:27.460 --> 09:32.110
sum for each row.

09:32.260 --> 09:33.290
All right.

09:34.720 --> 09:42.640
So let's go back to our initial array a and that's also the method thought process.

09:42.670 --> 09:46.580
So it takes the product over all elements.

09:46.590 --> 09:53.110
That's a bit a large number here actually and we can also take the product over all elements in each

09:53.110 --> 09:57.610
column so x equals zero.

09:57.630 --> 10:00.630
I guess that's the product of the column.

10:00.630 --> 10:02.890
So here we have 1 times five times line.

10:02.940 --> 10:08.470
Give us forty five and so on so two times six is twelve times ten is under 20.

10:08.550 --> 10:15.660
And yeah of course we can also take the product over all elements in each row by having the parameter

10:15.690 --> 10:19.550
X equals one.

10:19.600 --> 10:21.510
Now you can see it's the product here.

10:21.520 --> 10:22.600
Over each row.

10:22.600 --> 10:26.230
So one times two times three times four gets 24.

10:26.460 --> 10:26.680
Yeah.

10:26.680 --> 10:29.190
And so on.

10:29.200 --> 10:29.560
All right.

10:29.560 --> 10:34.490
So this is it for the session and in the next session we learn about boolean indexing.

10:34.570 --> 10:36.100
So I hope to see you there by.
